package com.lry.crawlers.cartoon.service.impl;

import com.lry.crawlers.cartoon.entity.CartoonVariable;
import com.lry.crawlers.cartoon.mapper.CartoonVariableMapper;
import com.lry.crawlers.cartoon.service.CartoonVariableService;
import com.lry.crawlers.util.ProcessVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class CartoonVariableServiceImpl implements CartoonVariableService {
    @Autowired
    CartoonVariableMapper cartoonVariableMapper;
    //初始化FictionVariable信息
    @PostConstruct
    private void initialize() {
        List<CartoonVariable> cartoonVariables = getCartoonVariables();
        for (CartoonVariable c: cartoonVariables){
            ProcessVariable.setCVariable(c.getId(),c);
        }

    }

    public void update(){
        initialize();
    }

    @Override
    public int setCartoonVariable(CartoonVariable cartoonVariable) {
        int insert = cartoonVariableMapper.insert(cartoonVariable);
        return insert;
    }

    @Override
    public List<CartoonVariable> getCartoonVariables() {
        return cartoonVariableMapper.selectList(null);
    }

}
